package zhihui.mobile.ui.register;

import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.zgm.utils.UiUtils;
import com.zgm.utils.ui.MyEditText;

import zhihui.mobile.R;
import zhihui.mobile.listener.EdDrawablePasswordListener;
import zhihui.mobile.presenter.IPresenter;
import zhihui.mobile.presenter.register.IPasswordContract;
import zhihui.mobile.presenter.register.PasswordFragmentPresenter;
import zhihui.mobile.presenter.register.RegisterPersenter;
import zhihui.mobile.ui.BaseFragment;

/**
 * Created by 张公铭 on 2017/7/12 0012.
 */

public class PasswordFragment extends BaseFragment implements IPasswordContract.IPasswordView
{
    private IPasswordContract.IPasswordPresenter passwordPresenter = new PasswordFragmentPresenter();
    private RegisterPersenter registerPersenter;
    private MyEditText ed_password;
    private Button btn_register;
    private TextView tv_msg;

    public void setRegisterPersenter(RegisterPersenter registerPersenter)
    {
        this.registerPersenter = registerPersenter;
    }

    @Override
    public void initView()
    {
        ed_password = (MyEditText) mView.findViewById(R.id.ed_register_password);
        UiUtils.editTextFocus(ed_password);
        ed_password.setDrawableRightListener(new EdDrawablePasswordListener(getContext()));

        btn_register = (Button) mView.findViewById(R.id.btn_register_password);
        btn_register.setOnClickListener(new View.OnClickListener()
        {
            @Override
            public void onClick(View v)
            {
                tv_msg.setText("");
                passwordPresenter.register(ed_password.getText().toString());
            }
        });

        tv_msg = (TextView) mView.findViewById(R.id.tv_password_msg);
        tv_msg.setText("'");
    }

    @Override
    protected int getLayoutResId()
    {
        return R.layout.register_password_fragment;
    }

    @Override
    protected IPresenter[] getPresenters()
    {
        return new IPresenter[]{passwordPresenter};
    }

    @Override
    protected void onInitPresenter()
    {
        passwordPresenter.init(this, getContext());
    }

    @Override
    public void showMessage(String message)
    {
        tv_msg.setText(message);
    }
}
